//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace.b;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import com.baidu.trace.am;

public final class d {
    private boolean a = false;
    private boolean b = false;
    private boolean c = false;
    private Handler d = null;
    private Context e = null;
    private f f = null;
    private h g = null;
    private g h = null;
    private am i = null;
    private i j = null;
    private static int k = -2147483648;
    private static boolean l = false;
    private static long m = 0L;

    public d() {
    }

    public static d a() {
        return d.a.a;
    }

    public final void a(Handler var1, Context var2) {
        this.d = var1;
        this.e = var2;
    }

    public final void b() {
        this.j = null;
        if(this.a) {
            this.a = false;
            if(this.f != null) {
                this.f.a();
                this.f = null;
            }
        }

        if(this.b) {
            this.b = false;
            if(this.h != null) {
                this.h.a();
            }
        }

        com.baidu.trace.b.a.e();
    }

    public final void c() {
        if(!this.a) {
            this.a = true;
            if(this.f != null) {
                this.f = null;
            }

            this.f = new f(this.e, this.d);
            this.f.start();
        }
    }

    protected final void d() {
        if(this.g != null) {
            this.g = null;
        }

        this.g = new h(this.d);
        this.g.start();
    }

    public final void e() {
        if(this.g != null) {
            this.g.a();
            this.g = null;
        }

    }

    public final void a(byte[] var1, com.baidu.trace.c.f.a var2) {
        if(this.j != null) {
            this.j = null;
        }

        this.j = new i(this.e, this.d, var1, var2);
        this.j.start();
    }

    public final void f() {
        this.c = false;
    }

    public final void a(String var1) {
        if(!this.c) {
            this.c = true;
            if(this.i != null) {
                this.i = null;
            }

            this.i = new am(0, var1);
            this.i.start();
        }
    }

    public final boolean g() {
        if(this.b) {
            return true;
        } else if(null == com.baidu.trace.b.a.b()) {
            if(this.d != null) {
                this.d.obtainMessage(4).sendToTarget();
            }

            return false;
        } else {
            this.b = true;
            this.h = new g(this.e, this.d);
            this.h.start();
            return true;
        }
    }

    public static boolean a(Context var0) {
        try {
            ConnectivityManager var5 = (ConnectivityManager)var0.getSystemService("connectivity");
            if(var5 == null) {
                com.baidu.trace.a.a("BaiduTraceSDK", "current network is not available");
                return false;
            } else {
                NetworkInfo var6 = var5.getActiveNetworkInfo();
                return var6 != null && var6.isConnected() && var6.isAvailable();
            }
        } catch (Exception var3) {
            com.baidu.trace.a.a("BaiduTraceSDK", "current network is not available");
            return false;
        } finally {
            ;
        }
    }

    protected static boolean a(int var0) {
        return var0 != k;
    }

    public static void b(int var0) {
        k = var0;
    }

    public static boolean h() {
        return l;
    }

    public static void a(boolean var0) {
        l = var0;
    }

    public static long i() {
        return m;
    }

    public static void a(long var0) {
        m = var0;
    }

    static class a {
        private static d a = new d();
    }
}
